package com.aijk.web.admin.controller;


import com.aijk.commons.utils.Collections3;
import com.aijk.medical.api.MedDoctorApi;
import com.aijk.medical.api.MedTeamApi;
import com.aijk.medical.model.qo.MedDoctorQo;
import com.aijk.medical.model.vo.MedDoctorVo;
import com.lifesea.familydoctor.model.FdTeam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by iscdw on 2016/4/18.
 */
@Controller
@RequestMapping("/")
public class MainController extends BaseController{

    @Autowired
    private MedDoctorApi medDoctorApi;

    @Autowired
    private MedTeamApi medTeamApi;

    @RequestMapping("/")
    public String main(Model model) {
        return "/welcome";
    }

    // 签约管理
    @RequestMapping("/sign")
    public String sign(@RequestParam String idcard, HttpServletRequest request, Model model) {
        String msg = "";
        MedDoctorQo qo = new MedDoctorQo();
        qo.setIdcard(idcard);
        List<MedDoctorVo> list = medDoctorApi.list(qo);

        if (Collections3.isEmpty(list)) {
            model.addAttribute("msg", "您还未注册成为家庭医生");
            return "/error/error_msg";
        }

        MedDoctorVo doctor = list.get(0);
        List<FdTeam> teams = medDoctorApi.findDoctorTeam(doctor.getIdcard());
        if (Collections3.isEmpty(teams)) {
            model.addAttribute("msg", "您还没有权限");
            return "/error/error_msg";
        }

        model.addAttribute("teamList", teams);
        return redirect("/medical/team/list?idcard="+idcard);
    }

    @RequestMapping("/statistic")
    public String statistic(Model model) {
        return redirect("/medical/base/statistic/listStreet");
    }

}
